package org.yenn.pattern.aliyun.behavioral.observer;

import org.junit.Before;
import org.junit.Test;
import org.yenn.pattern.aliyun.behavioral.observer.impl.BinaryObserver;
import org.yenn.pattern.aliyun.behavioral.observer.impl.HexaObserver;
import org.yenn.pattern.aliyun.behavioral.observer.impl.OctalObserver;

import static org.junit.Assert.*;

/**
 * 步骤 4
 * 使用 Subject 和实体观察者对象。
 */
public class ObserverPatternDemo {

    /**
     * 步骤 5
     * 验证输出。
     *
     * First state change: 15
     * Hex String: F
     * Octal String: 17
     * Binary String: 1111
     * Second state change: 10
     * Hex String: A
     * Octal String: 12
     * Binary String: 1010
     */
    @Test
    public void update() {
        Subject subject = new Subject();

        new HexaObserver(subject);
        new OctalObserver(subject);
        new BinaryObserver(subject);

        System.out.println("First state change: 15");
        subject.setState(15);
        System.out.println("Second state change: 10");
        subject.setState(10);
    }
}